﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace ZGameFramework.Config
{

    internal sealed class ConfigManager : GameFrameworkModule, IConfigManager
    {

        IConfigHelper m_ConfigHelper;

        public ConfigManager()
        {
            SetConfigHelper( new ConfigHepler() );
        }

        /// <summary>
        /// 获取游戏框架模块优先级。
        /// </summary>
        /// <remarks>优先级较高的模块会优先轮询，并且关闭操作会后进行。</remarks>
        internal override int Priority
        {
            get
            {
                return 0;
            }
        }

        /// <summary>
        /// 游戏框架模块轮询。
        /// </summary>
        /// <param name="elapseSeconds">逻辑流逝时间，以秒为单位。</param>
        /// <param name="realElapseSeconds">真实流逝时间，以秒为单位。</param>
        internal override void Update(float elapseSeconds, float realElapseSeconds)
        {
            
        }

        /// <summary>
        /// 关闭并清理游戏框架模块。
        /// </summary>
        internal override void Shutdown()
        {
            
        }


        public void SetConfigHelper(IConfigHelper configHelper)
        {
            if (null == configHelper)
            {
                return;
            }
            m_ConfigHelper = configHelper;
        }


        /// <summary>
        /// 加载数据
        /// </summary>
        public void Load()
        {
            if (null == m_ConfigHelper)
            {
                return;
            }

            m_ConfigHelper.Load();
        }

        /// <summary>
        /// 获取配置文件数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        public T GetCfgData<T>() where T : ConfigCfgData
        {
            if (null == m_ConfigHelper)
            {
                return null;
            }
            return m_ConfigHelper.GetCfgData<T>();
        }

    }

}
